/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ie.deloitte.cvapp.service;

import ie.deloitte.cvapp.dataaccess.EmployeeDAO;
import ie.deloitte.cvapp.dataaccess.EmployeeHasSkillDAO;
import ie.deloitte.cvapp.dataaccess.SkillDAO;
import ie.deloitte.cvapp.domain.Employee;
import ie.deloitte.cvapp.domain.EmployeeHasSkill;
import ie.deloitte.cvapp.domain.Skills;
import ie.deloitte.cvapp.form.CVSearchCriteria;
import ie.deloitte.cvapp.form.EmployeeBeanForm;
import ie.deloitte.cvapp.form.SkillBeanForm;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @author damorales
 */
@Service("cvService")
public class CVServiceImpl implements CVService {

	@Autowired
	private EmployeeDAO employeeDAO;
    @Autowired
   	private SkillDAO skillDAO;
    
    @Autowired
    private EmployeeHasSkillDAO employeeHasSkillDAO; 

	public void saveEmployee(EmployeeBeanForm eb) {
		Employee e = new Employee();
		// e.setIdEmployee(Integer.valueOf(eb.getIdEmployee()));
		e.setName(eb.getName());
		e.setEmail(eb.getEmail());
		e.setCreationdate(new Date(System.currentTimeMillis()));
		e.setSurname(eb.getSurname());
        e.setPrimarytelephone(eb.getPrimarytelephone());
        e.setSecondarytelepohne(eb.getSecondarytelepohne());
        e.setRoleproposed(eb.getRoleproposed());
        e.setProfile(eb.getProfile());
		employeeDAO.save(e);
    }

    public void saveSkill(SkillBeanForm sk) {
		Skills skill = new Skills();
		skill.setIdSkill(Integer.valueOf(sk.getIdSkill()));
		skill.setName(sk.getName());
		skillDAO.save(skill);
	}

    public EmployeeBeanForm findEmployee(String employeeId) {
    	return this.employeeDAO.getEmployeeBeanFormById(employeeId);
    }

	public List<Employee> findEmployeeByCriteria(CVSearchCriteria cvSearchCriteria) {
        System.out.println("FROM THE SERVICE!");
		return this.employeeDAO.search(cvSearchCriteria)    ;
    }

	public void updateEmployee(Employee e) {
		e.setCreationdate(new Date(System.currentTimeMillis()));
		// System.out.println("Here is the creation date");
		// System.out.println(e.getCreationdate());
		employeeDAO.save(e);
	}

	public List<Employee> getAllEmployees() {
		return this.employeeDAO.getAll();
	}
	
	public Employee findEmployeeById(String employeeId) {
		return this.employeeDAO.getById(employeeId);
    }
    
    public List<Skills> getAllSkills() {
		return this.skillDAO.getAll();
	}
    
    public Skills findSkillById(String idSkill) {
    	return this.skillDAO.getById(idSkill);
    }
    
    public void updateSkill(Skills skills){
    	skillDAO.save(skills);
    }
    
    public void saveEmployeeHasSkill(EmployeeHasSkill employee){
    	employeeHasSkillDAO.save(employee);

    }
}
